<?php

namespace app\admin\controller;

use app\model\Sysconfig;

class SysconfigController extends Base
{

	public function index()
	{
		$config = $this->request->post();
		$config['keyword'] = implode(',', $config['keyword']);

		if(!empty($config['domain'])){
			$config['domain'] = seturl($config['domain']);
		}
		

		$configstr = serialize($config);

		if (empty($config['id'])) {
			$data["weid"] = weid();
			$data["module"] = 'common';
			$data["status"] = 1;
			$data["settings"] = $configstr;

			Sysconfig::create($data);
		} else {

			Sysconfig::update(['settings' => $configstr], ['id' => $config['id']]);
		}
		return $this->json(['msg' => '操作成功']);
	}

	public function kefu()
	{
		$config = $this->request->post();

		$configstr = serialize($config);

		if (empty($config['id'])) {
			$data["weid"] = weid();
			$data["module"] = 'kefu';
			$data["status"] = 1;
			$data["settings"] = $configstr;

			Sysconfig::create($data);
		} else {

			Sysconfig::update(['settings' => $configstr], ['id' => $config['id']]);
		}
		return $this->json(['msg' => '操作成功']);
	}

	public function points()
	{
		$config = $this->request->post();

		$configstr = serialize($config);

		if (empty($config['id'])) {
			$data["weid"] = weid();
			$data["module"] = 'points';
			$data["status"] = 1;
			$data["settings"] = $configstr;

			Sysconfig::create($data);
		} else {

			Sysconfig::update(['settings' => $configstr], ['id' => $config['id']]);
		}
		return $this->json(['msg' => '操作成功']);
	}
	public function bottommenu()
	{
		$config = $this->request->post();

		$configstr = serialize($config);

		if (empty($config['id'])) {
			$data["weid"] = weid();
			$data["module"] = 'bottommenu';
			$data["status"] = 1;
			$data["settings"] = $configstr;

			Sysconfig::create($data);
		} else {

			Sysconfig::update(['settings' => $configstr], ['id' => $config['id']]);
		}
		return $this->json(['msg' => '操作成功']);
	}

	function getInfo()
	{
		$mo = input('post.mo');
		$res = Sysconfig::getconfig($mo);
		$res['keyword'] = explode(',', $res['keyword']);
		return $this->json(['data' => $res]);
	}
}
